package com.stone.framework.user.controller;

import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.stone.framework.message.PageReqMessage;
import com.stone.framework.message.PageResMessage;
import com.stone.framework.message.ReqMessage;
import com.stone.framework.message.ResMessage;
import com.stone.framework.message.user.RoleUserPageReqBody;
import com.stone.framework.message.user.RoleUserPageResBody;
import com.stone.framework.message.user.RoleUserReqBody;
import com.stone.framework.user.service.RoleUserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "角色用户")
@RestController
@RequestMapping("/roleuser")
public class RoleUserController {

    @Autowired
    private RoleUserService roleUserService;

    @ApiOperation(value = "根据角色获取", httpMethod = "POST")
    @PostMapping(value = "/getPage")
    PageResMessage<RoleUserPageResBody> getPage(@Valid @RequestBody PageReqMessage<RoleUserPageReqBody> reqMessage) {
        IPage<RoleUserPageResBody> page = roleUserService.queryPage(reqMessage.getBody(), reqMessage.buildPage());
        return PageResMessage.success(page);
    }

    @ApiOperation(value = "新增", httpMethod = "POST")
    @PostMapping(value = "/add")
    ResMessage<Void> add(@Valid @RequestBody ReqMessage<List<RoleUserReqBody>> reqMessage) {
        roleUserService.save(reqMessage.getBody());
        return ResMessage.success();
    }

    @ApiOperation(value = "刪除", httpMethod = "POST")
    @PostMapping(value = "/delete")
    ResMessage<Void> delete(@Valid @RequestBody ReqMessage<List<RoleUserReqBody>> reqMessage) {
        roleUserService.delete(reqMessage.getBody());
        return ResMessage.success();
    }

}
